package lesson01;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @Auther: xiaofei
 * @Date: 2021/6/28 - 06 - 28 - 16:22
 * @Description: lesson01
 * @version: 1.0
 */
public class UDPReceiveDemo01 {
    //这是一个main方法，是程序的入口：
    public static void main(String[] args) throws Exception {
        DatagramSocket socket = new DatagramSocket(6666);
        //准备接受包裹

        while(true){
            byte[] container = new byte[1024];

            DatagramPacket packet = new DatagramPacket(container,0,container.length);
            socket.receive(packet);
            byte[] data = packet.getData();
            String receiveDatas = new String(data, 0, data.length);
            System.out.println(receiveDatas);

            if(receiveDatas.equals("bye")){
                break;
            }
        }
    }
}
